import pymysql

conn = pymysql.connect(host="localhost",port=3306,user="root",password="zxc123!!",database="test_7_11",charset="utf8")

cursor = conn.cursor()
try:
    sql_1 = "insert into t_book(title, pub_date) values ('进击的巨人','2005-03-12')"
    cursor.execute(sql_1)
    conn.commit()
    print("生效行数=", conn.affected_rows())

except Exception as e:
    conn.rollback()
    print(e)

finally:
    cursor.close()
    conn.close()